/*
 * RegimenAgregarFrame.java
 *
 * Created on 29 de abril de 2008, 10:40 AM
 */
package org.contabilidad.regimen;

import org.mybeans.Sesion;
import org.mybeans.SubGrupoRegimenBeans;
import org.mybeans.RegimenBeans;
 
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

/**
 *
 * @author  avbravo
 */
public class RegimenAgregarFrame extends javax.swing.JFrame {

    Sesion sesion;
    RegimenBeans regimenBeans;
    SubGrupoRegimenBeans subGrupoRegimenBeans;
    String idSubGrupoRegimen = "";
    boolean  focoRegimen = false;

    /** Creates new form RegimenAgregarFrame */
    public RegimenAgregarFrame() {
        initComponents();
           /*
             * Fondo
             */

            
              
             

             
             

            /*
             * fin del fondo
             */
        sesion = new Sesion();
        regimenBeans = new RegimenBeans();
        subGrupoRegimenBeans = new SubGrupoRegimenBeans();
        
        CargarSubGrupoRegimen();
        AutoCompleteDecorator.decorate(this.jComboBoxSubGrupoRegimen);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldIdRegimen = new javax.swing.JTextField();
        jTextFieldRegimen = new javax.swing.JTextField();
        jTextFieldValor = new javax.swing.JTextField();
        jTextFieldLimiteInferior = new javax.swing.JTextField();
        jTextFieldLimiteSuperior = new javax.swing.JTextField();
        jTextFieldDescripcion = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaObservacion = new javax.swing.JTextArea();
        jButtonGuardar = new javax.swing.JButton();
        jButtonLimpiar = new javax.swing.JButton();
        jButtonVer = new javax.swing.JButton();
        jButtonRegresar = new javax.swing.JButton();
        jComboBoxSubGrupoRegimen = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Agregar Regimen ");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Codigo");

        jLabel2.setText("Regimen");

        jLabel3.setText("Cod. SubGrupo");

        jLabel5.setText("Valor");

        jLabel6.setText("Minimo");

        jLabel7.setText("Maximo");

        jLabel8.setText("Descripcion");

        jLabel9.setText("Observacion");

        jTextAreaObservacion.setColumns(20);
        jTextAreaObservacion.setRows(5);
        jScrollPane1.setViewportView(jTextAreaObservacion);

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/save.png"))); // NOI18N
        jButtonGuardar.setToolTipText("Guardar");
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        jButtonLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/escoba.png"))); // NOI18N
        jButtonLimpiar.setToolTipText("Limpiar los datos");
        jButtonLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimpiarActionPerformed(evt);
            }
        });

        jButtonVer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/view.png"))); // NOI18N
        jButtonVer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVerActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jComboBoxSubGrupoRegimen.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxSubGrupoRegimenItemStateChanged(evt);
            }
        });
        jComboBoxSubGrupoRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxSubGrupoRegimenActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(6, 6, 6)
                        .addComponent(jComboBoxSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 473, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(53, 53, 53)
                        .addComponent(jTextFieldIdRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(65, 65, 65)
                        .addComponent(jTextFieldRegimen, javax.swing.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel6)
                                .addGap(26, 26, 26)
                                .addComponent(jTextFieldLimiteInferior, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(32, 32, 32)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldLimiteSuperior, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonVer, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jComboBoxSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldIdRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldLimiteInferior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldLimiteSuperior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jButtonVer, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButtonLimpiar, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE))
                            .addGap(32, 32, 32)))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed

    try {
        String idRegimen = this.jTextFieldIdRegimen.getText();
        if (idRegimen == null || idRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el codigo de regimen", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldIdRegimen.requestFocus();
            return;
        }

        String Regimen = this.jTextFieldRegimen.getText();
        if (Regimen == null || Regimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el nombre del regimen", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldRegimen.requestFocus();
            return;
        }



        String sValor = this.jTextFieldValor.getText();
        double Valor = Double.parseDouble(sValor);
        if (Valor <= 0) {
            JOptionPane.showMessageDialog(this, "El valor no debe ser menor de 0.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldValor.setText("");
            jTextFieldValor.requestFocus();
            return;
        }
        String sLimiteInferior = this.jTextFieldLimiteInferior.getText();
        double LimiteInferior = Double.parseDouble(sLimiteInferior);
        if (LimiteInferior <= 0) {
            JOptionPane.showMessageDialog(this, "El limite inferior no debe ser negativo.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldLimiteInferior.setText("");
            jTextFieldLimiteInferior.requestFocus();
            return;
        }
        String sLimiteSuperior = this.jTextFieldLimiteSuperior.getText();
        double LimiteSuperior = Double.parseDouble(sLimiteSuperior);
        if (LimiteSuperior <= 0) {
            JOptionPane.showMessageDialog(this, "El limite superior no debe ser negativo.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldLimiteSuperior.setText("");
            jTextFieldLimiteSuperior.requestFocus();
            return;
        }
        if (Valor < LimiteInferior) {
            JOptionPane.showMessageDialog(this, "El Valor no debe ser menor que el limite inferior.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldValor.setText("");
            jTextFieldValor.requestFocus();
            return;

        }
        if (Valor > LimiteSuperior) {
            JOptionPane.showMessageDialog(this, "El Valor no debe ser mayor que el limite superior.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldValor.setText("");
            jTextFieldValor.requestFocus();
            return;

        }

        if (LimiteInferior > LimiteSuperior) {
            JOptionPane.showMessageDialog(this, "El limite inferior debe ser menor que el superior", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldLimiteInferior.setText("");
            jTextFieldLimiteInferior.requestFocus();
            return;

        }



        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String sqlquery = "select * from regimen where idmunicipio = ? and idregimen =?";
        PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
        psquery.setString(1, sesion.getIdmunicipio());
        psquery.setString(2, idRegimen);
        ResultSet rs = psquery.executeQuery();
        rs.next();
        int x = rs.getRow();

        if (x != 0) {
            JOptionPane.showMessageDialog(this, "Existe un regimen  con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);

            return;
        }

        String Descripcion = jTextFieldDescripcion.getText();
        String Observacion = jTextAreaObservacion.getText();
        String sql = "INSERT into regimen  VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
        PreparedStatement prest = sesion.con.prepareStatement(sql);


        prest.setString(1, idRegimen);
        prest.setString(2, idSubGrupoRegimen);
        prest.setString(3, Regimen);
        prest.setString(4, Descripcion);
        prest.setDouble(5, Valor);
        prest.setString(6, Observacion);
        prest.setString(7, sesion.getUsername());
        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
        prest.setDate(8, mydate);
        prest.setDouble(9, LimiteInferior);
        prest.setDouble(10, LimiteSuperior);
        prest.setString(11, sesion.getIdmunicipio());
        prest.setString(12, "si");

        int count = prest.executeUpdate();
        sesion.con.close();
        JOptionPane.showMessageDialog(this, "Regimen Guardado exitosamente", "Mensaje", JOptionPane.INFORMATION_MESSAGE);

    } catch (Exception ex) {
        System.out.println("Error" + ex);
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonGuardarActionPerformed

private void jButtonLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimpiarActionPerformed

    Limpiar();
}//GEN-LAST:event_jButtonLimpiarActionPerformed

private void jButtonVerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVerActionPerformed

    RegimenBusquedaFrame regimenBusquedaFrame = new RegimenBusquedaFrame();
    regimenBusquedaFrame.setLocationRelativeTo(null);
    regimenBusquedaFrame.setVisible(true);
}//GEN-LAST:event_jButtonVerActionPerformed

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed

    dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jComboBoxSubGrupoRegimenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxSubGrupoRegimenItemStateChanged
}//GEN-LAST:event_jComboBoxSubGrupoRegimenItemStateChanged

private void jComboBoxSubGrupoRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxSubGrupoRegimenActionPerformed

    try {
        String temp = (String) jComboBoxSubGrupoRegimen.getSelectedItem();
        int posicion = temp.indexOf("|");

        int posfinal = 0;
        if (posicion <= 0) {
            posfinal = 0;
        } else {
            posfinal = posicion - 1;
        }

        temp = temp.substring(0, posfinal);

        temp = temp.trim();
        jTextFieldIdRegimen.setText(temp);
        idSubGrupoRegimen = temp;
        CargarNombreSubGrupo(temp);

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error  " + ex.getMessage(), "ComboBox SubGrupoRegimen ActionPerformed", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jComboBoxSubGrupoRegimenActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new RegimenAgregarFrame().setVisible(true);
            }
        });
    }

    private void CargarNombreSubGrupo(String idsubgruporegimen) {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            idsubgruporegimen = idsubgruporegimen.trim();
            String sqlquery = "select subgrupo from subgruporegimen where idmunicipio='" + sesion.getIdmunicipio() + "' and activo='si' and idsubgruporegimen='" + idsubgruporegimen + "' ";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            int count = 0;
            String subgrupo = "";
            while (rs.next()) {
                subgrupo = rs.getString("subgrupo");
                count++;
            }
            if (count != 0) {
                jTextFieldRegimen.setText(subgrupo);
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error" + ex.getMessage(), "CargarRegimen() ", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void Limpiar() {

        this.jTextFieldIdRegimen.setText("");
        this.jTextFieldRegimen.setText("");
        this.jTextFieldDescripcion.setText("");
        jTextAreaObservacion.setText("");
        jTextFieldValor.setText("");
        jTextFieldLimiteInferior.setText("");
        jTextFieldLimiteSuperior.setText("");

    }

    private void CargarSubGrupoRegimen() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sqlquery = "select idsubgruporegimen, subgrupo from subgruporegimen where idmunicipio='" + sesion.getIdmunicipio() + "' and activo='si' order by idsubgruporegimen";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            jComboBoxSubGrupoRegimen.removeAllItems();
            int count = 0;
            while (rs.next()) {
                String idsubgruporegimen = rs.getString("idsubgruporegimen");
                if (count == 0) {
                    idSubGrupoRegimen = idsubgruporegimen;
                }
                idsubgruporegimen = idsubgruporegimen + " | " + rs.getString("subgrupo");
                jComboBoxSubGrupoRegimen.insertItemAt(idsubgruporegimen, count);
                count++;
            }
            if (count != 0) {
                jComboBoxSubGrupoRegimen.setSelectedIndex(0);
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error. CargarSubGrupoRegimen()", JOptionPane.ERROR_MESSAGE);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonLimpiar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JButton jButtonVer;
    private javax.swing.JComboBox jComboBoxSubGrupoRegimen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextAreaObservacion;
    private javax.swing.JTextField jTextFieldDescripcion;
    private javax.swing.JTextField jTextFieldIdRegimen;
    private javax.swing.JTextField jTextFieldLimiteInferior;
    private javax.swing.JTextField jTextFieldLimiteSuperior;
    private javax.swing.JTextField jTextFieldRegimen;
    private javax.swing.JTextField jTextFieldValor;
    // End of variables declaration//GEN-END:variables
}
